package com.yun.wemedia.service.impl;

import com.alibaba.nacos.client.naming.utils.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.model.wemedia.vos.WmChannelVO;
import com.yun.wemedia.mapper.WmChannelMapper;
import com.yun.wemedia.service.WmChannelService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author Excell
 * @description 针对表【wm_channel(频道信息表)】的数据库操作Service实现
 * @createDate 2025-07-23 08:25:36
 */
@Service
public class WmChannelServiceImpl extends ServiceImpl<WmChannelMapper, WmChannel>
        implements WmChannelService {

    @Override
    public List<WmChannelVO> findList() {
        List<WmChannel> wmChannels = list();

        if (CollectionUtils.isEmpty(wmChannels)) {
            return Collections.emptyList(); // 安全返回空集合，避免空指针
        }

        return wmChannels.stream()
                .filter(Objects::nonNull) // 防御性编程：避免空元素
                .map(channel -> {
                    WmChannelVO vo = new WmChannelVO();
                    BeanUtils.copyProperties(channel, vo);
                    return vo;
                })
                .collect(Collectors.toList());
    }

}




